<template>
	<view class="page">
		<view class="feedback-body">
			<textarea placeholder="请输入..." style="border-bottom:1px solid   #F1F1F3;" v-model="sendDate.content" class="feedback-textare" />
			</view>
        <choose :count="count"  :imgList="imgList"  @changes="fileChange"></choose>
        <compress  ref="compress" :maxwh="maxwh" :quality="quality" > </compress>


<!--        <view class="swiper-list">
            <view class="uni-list-cell uni-list-cell-pd feedback-title">
                <view class="uni-list-cell-db ">图片是否压缩</view>
                <switch :checked="isYasuo" @change="changeIndicatorDots" />
            </view>
        </view> -->
		<view class='feedback-title feedback-star-view'>
		    <text>插件评分</text>
		    <view class="feedback-star-view">
		        <text class="feedback-star" v-for="(value,key) in stars" :key="key" :class="key < sendDate.score ? 'active' : ''" @tap="chooseStar(value)"></text>
		    </view>
		</view>
        <view class='feedback-title'>
            <text>QQ/邮箱</text>
        </view>
        <view class="feedback-body">
            <input class="feedback-input" v-model="sendDate.contact" placeholder="(选填,方便我们联系你 )" />
        </view>

        <button type="default" style="font-size: 34upx; background-color: #DBA871;color:#ffffff !important;border-radius:6upx;" class="feedback-submit" @tap="send">提交</button>

    </view>
</template>

<script>
    import choose from "@/components/uni-publish/image/choose.vue"
    import compress from "@/components/uni-publish/image/compress.vue"
    export default {
        name:'newsPublish',
        components:{
        	choose,
            compress
        },
        data() {
            return {
                isYasuo:true,
                count:6,
                maxwh:280,
                quality:1, 
				//评价上传的图片
				uploudImgUrl:[],
				//订单里的商品
				products:[],
                
                msgContents: ["界面显示错乱", "启动缓慢，卡出翔了", "UI无法直视，丑哭了", "偶发性崩溃"],
                stars: [1, 2, 3, 4, 5],
                imgList: [],
                sendDate: {
                    score: 5,
                    content: "",
                    contact: ""
                }
            }
        },
        onLoad(options) {
			this.products=JSON.parse(options.order).lx_Self_OrdersSub;
        },
        methods: {
            compressImg(e){
              console.log(e)  
            },
            changeIndicatorDots(e){
            this.isYasuo = !this.isYasuo
            },
            fileChange(e){
              this.imgList=e;
              this.Upload();
            },
            chooseStar(e) { //点击评星
                this.sendDate.score = e;
            },
            previewImage() { //预览图片
                uni.previewImage({
                    urls: this.imgList
                });
            },
			
			//保存订单。
			Upload() {
				let that = this;
				//因为有一张图片， 输出下标[0]， 直接输出地址
				var imgFiles = this.imgList[0];
				// 上传图片
				// 做成一个上传对象
				var uper = uni.uploadFile({
					// 需要上传的地址
					url: 'http://localhost:9991/api/Lx_Self_Evaluate/UI_UserUpload',
					// filePath  需要上传的文件
					filePath: imgFiles,
					name: 'files',
					success(res1) {
						let resData = JSON.parse(res1.data).data;
						that.uploudImgUrl.push({SEvImg:resData.fileSmall});
					}
				});
				
			},
			
            send() { //发送提交
				let that=this;
				if(that.sendDate.content.trim()==""){
					uni.showToast({
						title: '请输入您的评价内容！',
						duration: 2000,
						mask: false,
						icon: "none"
					})
					return;
				}
				let uid = uni.getStorageSync("localUserId").userId;
				that.products.forEach((item,index)=>{
					let flag=index==that.products.length-1?true:false;
					that.saveData(item.osProId,flag)
				})

            },
			
			saveData(pdtId,isEnd){
				let that=this;
				let op = {
					url: "api/Lx_Self_Evaluate/UI_Add",
					data: {
						mainData: {
							EvWxId:0 ,
							EvProductId:pdtId,
							EvWxName:'name' ,
							EvWxHeadImg:'' ,
							EvScore:that.sendDate.score ,
							EvContent:that.sendDate.content ,
							EvContact:that.sendDate.contact ,
							EvEnable:0 ,
							EvDelFlag:0 ,
							CreatID:0 ,
							Creator:'' ,
							CreateDate:new Date() 
						}, 
						detailData: that.uploudImgUrl,
						delKeys: null
					}
				}
				this.$request.Post(op, (ret) => {
					
					if(isEnd){
						uni.showToast({
							title: ret.message,
							duration: 2000,
							mask: false,
							icon: "none"
						})
						//清空上传图片
						that.uploudImgUrl=[];
						
						uni.switchTab("/pages/order/order")
					}

				});
			}
        }
    }
</script>

<style>
    page {
        background-color: #EFEFF4;
    }

    .input-view {
        font-size: 28upx;
    }
    .close-view{
        text-align: center;line-height:14px;height: 16px;width: 16px;border-radius: 50%;background: #FF5053;color: #FFFFFF;position: absolute;top: -6px;right: -4px;font-size: 12px;
    }
</style>
